package org.infodavid.common.messaging;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.infodavid.common.messaging.MessagingService.IListener;

/**
 * The Class DefaultListener.
 */
public class DefaultListener implements IListener {
  /** The Constant LOG. */
  private static final Log LOG = LogFactory.getLog(DefaultListener.class);

  /** The messages. */
  private final List<Object> messages = new ArrayList<Object>();

  /**
   * Gets the received message list.
   * @return the received message list
   */
  public List<Object> getReceivedMessageList() {
    return messages;
  }

  /*
   * (non-Javadoc)
   * @see org.infodavid.common.messaging.MessagingService.IListener#onObjectMessage (java.lang.Object,
   * long, java.lang.String)
   */
  public boolean onObjectMessage(final Object object, final long timestamp, final String messageId)
      throws Exception {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Object message recieved at " + new Date(System.currentTimeMillis()));
    }

    getReceivedMessageList().add(object);

    return true;
  }

  /*
   * (non-Javadoc)
   * @see org.infodavid.common.messaging.MessagingService.IListener#onTextMessage (java.lang.String,
   * long, java.lang.String)
   */
  public boolean onTextMessage(final String text, final long timestamp, final String messageId)
      throws Exception {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Text message recieved at " + new Date(System.currentTimeMillis()));
    }

    getReceivedMessageList().add(text);

    return true;
  }
}
